# -*- coding: utf-8 -*-
# ©  2015-2019 Deltatech
# See README.rst file on addons root folder for license details




from odoo import models, fields, api, tools, _
from odoo.exceptions import UserError, RedirectWarning



class stock_quant(models.Model):
    _inherit = "stock.quant"


    @api.model
    def _update_available_quantity(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, in_date=None):

        if location_id.usage == 'internal' and (product_id.qty_available + quantity) < 0:
            if location_id.company_id.no_negative_stock:
                raise UserError(_('%s 在 %s 位置 仅有 %s, 操作后库存将变为 %s.')% \
                        (product_id.name, location_id.name,product_id.qty_available,  quantity))


        return super(stock_quant,self)._update_available_quantity( product_id, location_id, quantity, lot_id, package_id, owner_id,in_date)


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
